package com.ruoyi.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EquipmentMaintenanceDetail;
import com.ruoyi.system.service.IEquipmentMaintenanceDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * maintenanceController
 *
 * @author admin
 * @date 2020-07-20
 */
@Controller
@RequestMapping("/system/maintenancedetail")
public class EquipmentMaintenanceDetailController extends BaseController
{
    private String prefix = "system/maintenancedetail";

    @Autowired
    private IEquipmentMaintenanceDetailService equipmentMaintenanceDetailService;

    @RequiresPermissions("system:maintenancedetail:view")
    @GetMapping()
    public String maintenancedetail()
    {
        return prefix + "/maintenancedetail";
    }

    /**
     * 查询maintenance列表
     */
    @RequiresPermissions("system:maintenancedetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EquipmentMaintenanceDetail equipmentMaintenanceDetail)
    {
        startPage();
        List<EquipmentMaintenanceDetail> list = equipmentMaintenanceDetailService.selectEquipmentMaintenanceDetailList(equipmentMaintenanceDetail);
        return getDataTable(list);
    }

    @GetMapping("/justdetail/list/{id}")
    public String goMaintenanceList(@PathVariable String id,String carno,ModelMap mmap){
        mmap.put("mid",id);
        mmap.put("carno",carno);
        return prefix + "/justmaintenancedetail";
    }

    /**
     * 导出maintenance列表
     */
    @RequiresPermissions("system:maintenancedetail:export")
    @Log(title = "maintenance", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EquipmentMaintenanceDetail equipmentMaintenanceDetail)
    {
        List<EquipmentMaintenanceDetail> list = equipmentMaintenanceDetailService.selectEquipmentMaintenanceDetailList(equipmentMaintenanceDetail);
        ExcelUtil<EquipmentMaintenanceDetail> util = new ExcelUtil<EquipmentMaintenanceDetail>(EquipmentMaintenanceDetail.class);
        return util.exportExcel(list, "maintenancedetail");
    }

    /**
     * 新增maintenance
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存maintenance
     */
    @RequiresPermissions("system:maintenancedetail:add")
    @Log(title = "maintenance", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EquipmentMaintenanceDetail equipmentMaintenanceDetail)
    {
        return toAjax(equipmentMaintenanceDetailService.insertEquipmentMaintenanceDetail(equipmentMaintenanceDetail));
    }

    /**
     * 修改maintenance
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EquipmentMaintenanceDetail equipmentMaintenanceDetail = equipmentMaintenanceDetailService.selectEquipmentMaintenanceDetailById(id);
        mmap.put("equipmentMaintenanceDetail", equipmentMaintenanceDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存maintenance
     */
    @RequiresPermissions("system:maintenancedetail:edit")
    @Log(title = "maintenance", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EquipmentMaintenanceDetail equipmentMaintenanceDetail)
    {
        return toAjax(equipmentMaintenanceDetailService.updateEquipmentMaintenanceDetail(equipmentMaintenanceDetail));
    }

    /**
     * 删除maintenance
     */
    @RequiresPermissions("system:maintenancedetail:remove")
    @Log(title = "maintenance", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(equipmentMaintenanceDetailService.deleteEquipmentMaintenanceDetailByIds(ids));
    }
}
